﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TomShane.Neoforce.Controls;

namespace SpaceInvade
{
    public static class Sound
    {
        //Init effect and music variables
        private static Song sngMenu = null;
        private static Song inGameOne = null;
        private static Song inGameTwo = null;
        private static SoundEffect sndPlayerBullet = null;
        private static SoundEffect sndPlayerExplode = null;
        private static SoundEffect sndEnemyExplode = null;
        private static SoundEffect sndEnemyHit = null;

        private static Song currentSong = null;
        static Manager Manager;

        //Public Sound functions
        public static void InitSound(Manager manager)
        {
            Manager = manager;
            // Initialize the music
            sngMenu = Manager.Content.Load<Song>(@"Music/MENU");
            inGameOne = Manager.Content.Load<Song>(@"Music/song1");
            inGameTwo = Manager.Content.Load<Song>(@"Music/song2");
            
            //Initialize the effects
            sndPlayerBullet = Manager.Content.Load<SoundEffect>(@"SndEffects/playerShoot");
            sndPlayerExplode = Manager.Content.Load<SoundEffect>(@"SndEffects/playerExplode");
            sndEnemyExplode = Manager.Content.Load<SoundEffect>(@"SndEffects/enemyExplode");
            sndEnemyHit = Manager.Content.Load<SoundEffect>(@"SndEffects/enemyHit");
        }

        public static void PlayEffect(string effectName)
        {
            switch (effectName)
            {
                case "efctPBSHOOT":
                    // Player bullet shoot sound effect
                    sndPlayerBullet.Play();
                    break;
                case "efctENEMYHIT":
                    // Player bullet hit enemy ship sound effect
                    sndEnemyHit.Play();
                    break;
                case "efctENEMYEXPLODE":
                    // Enemy dead sound effect
                    sndEnemyExplode.Play();
                    break;
                case "efctPEXPLODE":
                    // Player dead sound effect
                    sndPlayerExplode.Play();
                    break;
                default:
                    break;
            }
        }

        public static void PlaySong(string songName)
        {
            // Set the music to always loop
            MediaPlayer.IsRepeating = true;

            switch (songName)
            {
                case "sngMenu":
                    MediaPlayer.Stop();
                    MediaPlayer.Play(sngMenu);
                    currentSong = sngMenu;
                    break;
                case "music1":
                    MediaPlayer.Stop();
                    MediaPlayer.Play(inGameOne);
                    currentSong = inGameOne;
                    break;
                case "music2":
                    MediaPlayer.Stop();
                    MediaPlayer.Play(inGameTwo);
                    currentSong = inGameTwo;
                    break;
                default:
                    break;
            }
        }

        public static void IsSongPlaying(string songName, bool setToPlay = true)
        {
        }

        public static void StopAllMusic()
        {
            MediaPlayer.Stop();
        }

        public static void MusicVolume(float volume)
        {
            MediaPlayer.Volume = volume;
        }

        public static void Dispose()
        {
            StopAllMusic();
        }
    }
}
